<?php
$studentName = $_POST['student_name'] ?? '';
$studentSex = $_POST['student_sex'] ?? '';
$studentBirthday = $_POST['student_birthday'] ?? '';
$studentAddress = $_POST['student_address'] ?? '';
$classId = $_POST['class_id'] ?? 0;

$dsn = "sqlsrv:Server=LAPTOP-LD8O4C6L\SQLEXPRESS;Database=Student";
$db = new PDO($dsn, "sa", "123456");

$sql = "insert into Student (StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) 
	values ('{$studentName}', '{$studentSex}', '{$studentBirthday}', '{$studentAddress}', {$classId});";
$result = $db->exec($sql);
if ($result){
    echo "添加成功返回上一级<a href='student_list.php'>返回列表页</a>";
}else{
    echo "添加失败";
}